package zsh
import (
"strings"
"github.com/rsteube/carapace/internal/env"
)
type namedDirectories map [string ]string
var NamedDirectories = make (namedDirectories )
func (nd *namedDirectories ) match (s string ) string {
if strings .HasPrefix (s , "~" ) && !strings .HasPrefix (s , "~/" ) && strings .Contains (s , "/" ) {
return NamedDirectories [strings .SplitN (s , "/" , 2 )[0 ][1 :]]
}
return ""
}
func (nd *namedDirectories ) Matches (s string ) bool {
return nd .match (s ) != ""
}
func (nd *namedDirectories ) Replace (s string ) string {
if match := nd .match (s ); match != "" {
if !strings .HasSuffix (match , "/" ) {
match = match + "/"
}
return match + strings .SplitN (s , "/" , 2 )[1 ]
}
return s
}
func init() {
if hashDirs := env .Hashdirs (); hashDirs != "" {
for _ , line := range strings .Split (hashDirs , "\n" ) {
if splitted := strings .SplitN (line , "=" , 2 ); len (splitted ) == 2 {
NamedDirectories [splitted [0 ]] = splitted [1 ]
}
}
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .